/*
 * 文件名:Globel.cpp
 *
 * 	 功能描述:
 *  创建日期: 2010-12-12
 *  版本Ver0.01
 *  作者: huanying2000
 *  版权:copyright 2010 by the Camellia project 
 *  free software under the terms of the LGPL 2.1
 */
#include "Globel.hpp"

bool stringConvert(char *outputStr, char *inputStr, const char *tocode, const char *fromcode)
{
    iconv_t cd;
    size_t inputLeft = strlen(inputStr);
    size_t outputLen = inputLeft * GBK_UTF8_RATE;
    size_t *inbytesleft = &inputLeft;
    size_t *outbytesleft = &outputLen;

    cd = iconv_open(tocode, fromcode);
    iconv(cd, &inputStr, inbytesleft, &outputStr, outbytesleft);
    iconv_close(cd);

    if (0 == errno)
        return true;
    else
        return false;
}

ostream& operator<<(ostream &out, KAudioInfo &audioInfo)
{
	cout << "===Audio information===\n"
			<< "Decoder:\t" << audioInfo.mpegLayer << '\n'
			<< "Mode:\t\t" << audioInfo.mode << '\n'
			<< "sample:\t\t" << audioInfo.sampleRate << " Hz\n"
			<< "bite rate:\t" << audioInfo.bitrRate << " kbps\n"
			<< "duration:\t" << (audioInfo.duration / 60) << ":" << (audioInfo.duration % 60) << '\n'
			<< "tpf:\t\t" << audioInfo.timePerFrame << '\n'
			<< "===Audio information===\n";

	return out;
}

ostream& operator<<(ostream &out, KAudioTag &audioTag)
{
	cout << "===Audio Tags===\n"
			<< "标题：\t\t" << audioTag.title << '\n'
			<< "作者：\t\t" << audioTag.artist << '\n'
			<< "专辑：\t\t" << audioTag.album << '\n'
			<< "出品年代：\t" << audioTag.year << '\n'
			<< "曲目号：\t" << audioTag.trace << '\n'
			<< "类型：\t\t" << audioTag.genre << '\n'
			<< "备注：\t\t" << audioTag.comment << '\n'
			<< "内嵌歌词：\t" << audioTag.innerLyric << '\n'
			<< "===Audio Tags===\n";

	return out;
}
